//
//  HDItemBaseVC.m
//  HDHuNanMuseum
//
//  Created by liuyi on 2017/9/2.
//  Copyright © 2017年 liuyi. All rights reserved.
//

#import "HDItemBaseVC.h"
#import "NavigationTitleView.h"
//#import "HD_LY_LoginVC.h"

@interface HDItemBaseVC ()

@property (nonatomic, strong) NavigationTitleView *myTitleLabel;

@end

@implementation HDItemBaseVC

- (void)viewDidLoad {
    [super viewDidLoad];
    declare = [HDDeclare sharedDeclare];
    //消除ScrollView与导航栏中间的间隔
    self.automaticallyAdjustsScrollViewInsets = false;
    if ([self respondsToSelector:@selector(setNeedsStatusBarAppearanceUpdate)]) {
        [self prefersStatusBarHidden];
        [self performSelector:@selector(setNeedsStatusBarAppearanceUpdate)];
    }
    UIButton *leftButton = [UIButton buttonWithType:UIButtonTypeCustom];
    leftButton.frame = CGRectMake(0.0, 0.0, 45, 45);
    leftButton.imageEdgeInsets = UIEdgeInsetsMake(0, -15, 0, 10);//UIEdgeInsetsMake(<#CGFloat top#>, <#CGFloat left#>, <#CGFloat bottom#>, <#CGFloat right#>)

    [leftButton setImage:[UIImage imageNamed:@"nav_back"] forState:UIControlStateNormal];
    [leftButton addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *leftBarButtonItem =[[UIBarButtonItem alloc]initWithCustomView:leftButton];
    [self.navigationItem setLeftBarButtonItem:leftBarButtonItem];
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    UINavigationBar *navigationBar = self.navigationController.navigationBar;
    [navigationBar setBackgroundImage:[UIImage imageNamed:@"nav_bar"]
                       forBarPosition:UIBarPositionAny
                           barMetrics:UIBarMetricsDefault];
    [navigationBar setShadowImage:[UIImage new]];
    
    navigationBar.tintColor = [UIColor whiteColor];
    NSMutableDictionary *attributes= [[NSMutableDictionary alloc] init];
    [attributes setValue:[UIColor whiteColor] forKey:NSBackgroundColorAttributeName];
    [self.navigationController.navigationBar setTitleTextAttributes:attributes];
    self.navigationController.navigationBarHidden = YES;
    
}

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];

}

#pragma mark --- Nav Title -----
- (void)setTitle:(NSString *)title {
    dispatch_async(dispatch_get_main_queue(), ^{
        [self titleRelease];
        _myTitleLabel = [[NavigationTitleView alloc]init];
        _myTitleLabel.frame = CGRectMake(60, 0, ScreenWidth-120 , 44);
        
        NSString *myTitle = title;
        if (title.length == 0)
            myTitle = @" ";
        _myTitleLabel.titleName = myTitle;
        _myTitleLabel.titleColor = [UIColor whiteColor];
        _myTitleLabel.titleFont = fengzhengFont(20);
        _myTitleLabel.backgroundColor = [UIColor clearColor];
        self.navigationItem.titleView = _myTitleLabel;
        
    });
}

- (void)titleRelease {
    [_myTitleLabel removeFromSuperview];
    self.myTitleLabel = nil;
}

#pragma mark --- Public Methods ----

// 所有未登录的页面，跳转到登录页面
- (void)pushToLoginVC:(UIViewController *)vc {
//    HD_LY_LoginVC *login = [[UIStoryboard storyboardWithName:@"Login" bundle:nil] instantiateViewControllerWithIdentifier:@"HD_LY_LoginVC"];
//    [vc presentViewController:login animated:YES completion:nil];
}

#pragma mark -------- Bar Methods --------
- (BOOL) prefersStatusBarHidden {
    return NO;
}

- (UIStatusBarStyle)preferredStatusBarStyle {
    return UIStatusBarStyleDefault;
}

-(void)back {
    //[HD_NKM_Mediator setNowVCDescription:nil]; // 用于蓝牙收号
    [self titleRelease];
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
